package com.algorithm.queue;

import java.util.Scanner;

/**
 * Created by mu on 2018/2/6.
 */
public class Circle {
    public static void main(String[] args) {
        int n,s;
        Scanner scanner = new Scanner(System.in);
        n=scanner.nextInt();
        s=scanner.nextInt();
        
        int [] circle=new int[n+1];
        for (int i = 0; i < circle.length; i++) {
            circle[i]=i;
        }
        Josephus(circle,n,s);
    }

    /**
     * 约瑟夫环
     * @param circle
     * @param n
     * @param s
     */
    private static void Josephus(int[] circle, int n, int s) {
        int front=0,real=circle.length-1;
        while(front!=real){

            for(int i=0;i<s-1;i++){
                front=(front+1)%circle.length;
                real=(real+1)%circle.length;
                circle[real]=circle[front];
            }
            front=(front+1)%circle.length;
            System.out.println(circle[front]);
        }
    }
}
